package objects;

import objects.misc.Gadget;
import objects.misc.PodejrzewamZeToHack;

import com.badlogic.gdx.math.Vector2;

public class Human extends UnrealObject {
	public enum CLASS {
		Zwiadowca, Snajper, Medyk, Spieg, Komandos
	};
	
	/* ogolnie jak primitive - zostawiamy na public - bezposrednio modyfikuje 
	 * a jak Obiekt - napiszemy getter i setter
	 * */
	public float predkosc;   /* jednostka pixel na sekunde */
	public float hp;
	public float atk;
	public final CLASS char_class;
	public final int team_id;
	
	private Vector2 bound;
	private Vector2 last_position; /* pozycja na skali mapy, nie ekranu */
	
	private Vector2 moveVector;
	private float damageTaken; 
	private float maxhp;
	
	private Gadget[] gadget_list;

	public Human (int id, int team_id, CLASS char_class) {
		int slot = 2;
		Gadget special_gadget = null;
		switch (char_class) {
			case Zwiadowca: {
				setup(5,100,100, new Vector2(10,10) ); /* testowe dane */
			//	special_gadget = new Gadget();/* testowe dane */
				break;
			}
			case Snajper: {
				break;
			}
			case Medyk: {
				break;
			}
			case Spieg: {
				break;
			}
			case Komandos: {
				slot = 3;
				break;
			}
			default: {
				throw new RuntimeException("Invalid class");
			}
		}
		super.id = id;
		this.team_id = team_id;
		this.char_class = char_class;
		gadget_list = new Gadget[slot];
		if( special_gadget != null ) {
			gadget_list[0] = special_gadget; /* testowe dane */
		}
	}
	
	private void setup( float predkosc, float hp, float atk, Vector2 bound) {
		this.predkosc = predkosc;
		this.hp = hp;
		this.maxhp = hp;
		this.atk = atk;
		this.bound = bound;
	}
	
	
	public Gadget getGadget(int index) throws PodejrzewamZeToHack {
		if(  index <0 || index >= gadget_list.length ) throw new PodejrzewamZeToHack();
		return gadget_list[index];
	}
	
	public void setGadget(int index,Gadget gadget ) throws PodejrzewamZeToHack {
		if(  index <0 || index >= gadget_list.length ) throw new PodejrzewamZeToHack();
		gadget_list[index] = gadget;
	}
	
	public void dropGadget(int index ) throws PodejrzewamZeToHack {
		if ( char_class != CLASS.Komandos && index == 0 ) throw new PodejrzewamZeToHack();
		if(  index <0 || index >= gadget_list.length ) throw new PodejrzewamZeToHack();
		gadget_list[index].free();
		gadget_list[index] = null;
	}
	
	@Override
	public boolean isPushable() {
		return true;
	}
	
	public Vector2 getBound() {
		return bound;
	}
	
	
	public Vector2 getLastPosition() {
		if (last_position == null ) last_position = new Vector2();
		return last_position;
	}

	@Override
	public Vector2 getMoveVector() {
		if (moveVector == null ) moveVector = new Vector2();
		return moveVector;
	}

	@Override
	public void doUpdate() {
		last_position.set(position);
		position.add(moveVector);
		moveVector.set(0,0);
		hp -= damageTaken;
		if ( hp < 0 ) hp = 0;
		if ( hp > maxhp ) hp = maxhp;
		
	}

	@Override
	public void setActive(boolean k) {
		super.active = k;
	}

	@Override
	public boolean isActive() {
		return super.active;
	}
	
}
